package com.example.luhenchang_pdf.pdfutils;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

import com.example.luhenchang_pdf.R;
import com.github.barteksc.pdfviewer.PDFView;

import java.io.File;

public class PdfActivity extends Activity {
	
	private PDFView pdfView ; //读取pdf文件内容显示的控件
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_pdf);
		init();
	}

	/**
	 * 初始化操作
	 */
	private void init() {
		initView();
		initData();
	}

	/**
	 * 初始化数据
	 */
	private void initData() {
		Intent intent = getIntent();
		String path = intent.getStringExtra("path");
		readPdfContent(path);
	}

	/**
	 * 初始化控件
	 */
	private void initView() {
        pdfView = findViewById(R.id.pdfView);
		
	}
	
	/**
	 * 读取Pdf文件的内容
	 * @param path :文件地址
	 */
	public void readPdfContent(String path){
        /*pdfView.fromUri(Uri)
        or
        pdfView.fromFile(File)
        or
        pdfView.fromBytes(byte[])
        or
        pdfView.fromStream(InputStream) // stream is written to bytearray - native code cannot use Java Streams
        or
        pdfView.fromSource(DocumentSource)
        fromAsset
        or*/
        Log.e("pathload",path.toString());
        pdfView.fromFile(new File(path))
                .pages(0, 2, 1, 3, 3, 3) // all pages are displayed by default
                .enableSwipe(true) // allows to block changing pages using swipe
                .swipeHorizontal(false)
                .enableDoubletap(true)
                .defaultPage(0)
                // allows to draw something on the current page, usually visible in the middle of the screen
                /*.onDraw(onDrawListener)
                // allows to draw something on all pages, separately for every page. Called only for visible pages
                .onDrawAll(onDrawListener)
                .onLoad(onLoadCompleteListener) // called after document is loaded and starts to be rendered
                .onPageChange(onPageChangeListener)
                .onPageScroll(onPageScrollListener)
                .onError(onErrorListener)
                .onPageError(onPageErrorListener)
                .onRender(onRenderListener) // called after document is rendered for the first time
                // called on single tap, return true if handled, false to toggle scroll handle visibility
                .onTap(onTapListener)
                .onLongPress(onLongPressListener)*/
                .enableAnnotationRendering(false) // render annotations (such as comments, colors or forms)
                .password(null)
                .scrollHandle(null)
                .enableAntialiasing(true) // improve rendering a little bit on low-res screens
                // spacing between pages in dp. To define spacing color, set view background
                .spacing(0)
                .autoSpacing(false) // add dynamic spacing to fit each page on its own on the screen
                /*.linkHandler(DefaultLinkHandler)
                .pageFitPolicy(FitPolicy.WIDTH)*/
                .pageSnap(true) // snap pages to screen boundaries
                .pageFling(false) // make a fling change only a single page like ViewPager
                .nightMode(false) // toggle night mode
                .load();
	}
	
	
	
}
